package wechat.rcv.controller;

import com.shrcl.engineerprocess.domain.EngineerProjectAssignment;
import edu.fudan.mylang.pf.IObjectFactory;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import wechat.rcv.controller.StatusResponse;

@RestController
@Transactional
@ResponseBody
@SuppressWarnings("all")
public class CommitSummary {
  private final static Logger logger = Logger.getLogger(CommitSummary.class.getName());
  
  @Autowired
  private IObjectFactory entities;
  
  @RequestMapping(value = "/commitsummary", method = RequestMethod.POST)
  public StatusResponse process(final Long assignmentId, final String summary) {
    CommitSummary.logger.info("=========>CommitSummary.processs<============");
    CommitSummary.logger.info(("=========>CommitSummary.assignmentId<============" + assignmentId));
    CommitSummary.logger.info(("=========>CommitSummary.summary<============" + summary));
    final StatusResponse result = new StatusResponse();
    try {
      final EngineerProjectAssignment a = this.entities.<EngineerProjectAssignment>get(EngineerProjectAssignment.class, assignmentId);
      a.doSummary(summary);
      a.finish();
      result.success = Boolean.valueOf(true);
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        result.success = Boolean.valueOf(false);
        e.printStackTrace();
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
    return result;
  }
}
